/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.raitcon.hibernate.db;

import com.raitcon.hibernate.bean.Anio;
import com.raitcon.hibernate.factory.HibernateUtil;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author Mike
 */
public class AnioDB {
    
    private static final Log log = LogFactory.getLog(AnioDB.class);
        
        private Session session=null;
	

        
        public AnioDB(){
             this.session = HibernateUtil.getSessionFactory().getCurrentSession();
        }
	
	
	       
        
     public List getAnioAll() {
        List<Anio> anioList = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery ("from Anio as anio order by 1");
            anioList = (List<Anio>) q.list();
            log.info("Se consulto exitosamente la tabla Año");
        } catch (Exception e) {
            log.error("Error:"+e.getMessage());
            e.printStackTrace();
            
        }
        return anioList;
      } 
      
     public String  getAnioById(Integer idAnio) {
        
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery ("FROM  Anio as anio  WHERE id_anio= "+idAnio);
            String descAnio= ((Anio) q.uniqueResult()).getDescripcion()+"";
            log.info("descAnio::"+descAnio);
            return descAnio;
        } catch (Exception e) {
            log.error("Error:"+e.getMessage());
            e.printStackTrace();
            
        }
        return null;
      } 
}
